<template>
<div class="list">
    <!--搜索表单-->
    <div class="common-seach-wrap">
      <el-form
        size="small"
        :inline="true"
        :model="searchForm"
        class="demo-form-inline"
      >
        <el-form-item
          ><el-input
            size="small"
            v-model="searchForm.order_no"
            :placeholder="$t('plus.input_order_no')"
          ></el-input
        ></el-form-item>
        <el-form-item
          ><el-input
            size="small"
            v-model="searchForm.room_name"
            :placeholder="$t('plus.input_room_name')"
          ></el-input
        ></el-form-item>
        <el-form-item
          ><el-input
            size="small"
            v-model="searchForm.real_name"
            :placeholder="$t('plus.input_host_name')"
          ></el-input
        ></el-form-item>
        <el-form-item
          ><el-input
            size="small"
            v-model="searchForm.supplier_name"
            :placeholder="$t('plus.input_merchant_name')"
          ></el-input
        ></el-form-item>
        <el-form-item>
          <el-button
            size="small"
            type="primary"
            icon="Search"
            @click="searchSubmit"
            >{{$t('plus.search')}}</el-button
          >
        </el-form-item>
      </el-form>
    </div>

    <!--内容-->
    <div class="product-content">
      <div class="table-wrap">
        <el-table
          size="small"
          :data="tableData"
          border
          style="width: 100%"
          v-loading="loading"
        >
          <el-table-column prop="orderNo" :label="$t('plus.order_number')"></el-table-column>
          <el-table-column prop="nickName" :label="$t('plus.buyer2')"></el-table-column>
          <el-table-column
            prop="roomUserNickName"
            :label="$t('plus.host_name')"
          ></el-table-column>
          <el-table-column prop="supplierName" :label="$t('plus.merchant')"></el-table-column>
          <el-table-column
            prop="productList[0].productName"
            :label="$t('plus.product_name')"
            width="200"
          ></el-table-column>
          <el-table-column prop="roomName" :label="$t('plus.live_room1')"></el-table-column>
          <el-table-column
            prop="payPrice"
            :label="$t('plus.order_amount')"
            width="100"
          ></el-table-column>
          <el-table-column prop="stateText" :label="$t('plus.order_status')"></el-table-column>
          <el-table-column prop="createTime" :label="$t('plus.order_time')"></el-table-column>
          <el-table-column fixed="right" :label="$t('plus.action')">
            <template #default="scope">
              <el-button
                type="text"
                size="small"
                @click="openDetail(scope.row)"
                v-auth="'/order/order/detail'"
                >{{$t('plus.details')}}</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!--分页-->
      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
          :current-page="curPage"
          :page-size="pageSize"
          layout="total, prev, pager, next, jumper"
          :total="totalDataNumber"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import liveApi from "@/api/live.js";
export default {
  components: {},
  inject: ["reload"],
  data() {
    return {
      /*是否加载完成*/
      loading: false,
      /*列表数据*/
      tableData: [],
      /*一页多少条*/
      pageSize: 20,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      /*横向表单数据模型*/
      searchForm: {
        orderNo: "",
        roomName: "",
        realName: "",
        supplierName: ""
      }
    };
  },
  created() {
    /*获取列表*/
    this.getTableList();
  },
  methods: {
    /*搜索*/
    searchSubmit() {
      this.curPage = 1;
      this.getTableList();
    },
    /*选择第几页*/
    handleCurrentChange(val) {
      let self = this;
      self.curPage = val;
      self.getTableList();
    },
    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getTableList();
    },
    /*获取列表*/
    getTableList() {
      let self = this;
      let Params = self.searchForm;
      Params.pageIndex = self.curPage;
      Params.pageSize = self.pageSize;
      self.loading = true;
      liveApi.getOrderList(Params, true).then(res => {
        self.loading = false;
        self.tableData = res.data.records;
        self.totalDataNumber = res.data.total;
      }).catch(error => {
        self.loading = false;
      });
    },
    /*打开详情*/
    openDetail(row) {
      let self = this;
      let params = row.orderId;
      self.$router.push({
        path: "/order/order/Detail",
        query: {
          orderId: params
        }
      });
    }
  }
};
</script>

